home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol260 / compstr.pqs / comp-str.pas
Encoding:
Pascal/Delphi Source File  |  1986-08-27  |  3.6 KB  |  63 lines

  1. { Turbo 3.x Compare Strings Function
  2.   Copyright (C) July 7, 1986 by Mark Brandon [72477,1546]
  3.  
  4.   This function compares 2 string variables and returns a TRUE/FALSE
  5.   condition based upon the comparison operation (LT,EQ,GT).  The
  6.   comparison is performed using the uppercase of the strings; convert
  7.   the two AND  AL,$5F to NOPs ($90) if you don't want uppercase con-
  8.   version.  Untyped strings are used to allow strings of any length.
  9.   This function is more suited to use in IF statements than the other
  10.   compare strings function that is in DL 1. }
  11.  
  12. TYPE   compare_opcode = (LT,EQ,GT);
  13. CONST  resultable : ARRAY[0..8] OF BOOLEAN = (TRUE,FALSE,FALSE,  {LT}
  14.                                               FALSE,TRUE,FALSE,  {EQ}
  15.                                               FALSE,FALSE,TRUE); {GT}
  16.  
  17. FUNCTION CompStrs(VAR string1; operation:compare_opcode;
  18.                   VAR string2): BOOLEAN;
  19. BEGIN
  20.  Inline(                      { inline code created with the INLINE Assembler }
  21.    $1E                        {         PUSH DS}
  22.   /$C4/$76/<STRING1           {         LES  SI,<string1[BP]}
  23.   /$26/$AC                    {     ES: LODSB}
  24.   /$89/$F7                    {         MOV  DI,SI               ; ES:DI = string 1}
  25.   /$88/$C2                    {         MOV  DL,AL               ; DL = LENGTH(string1)}
  26.   /$C5/$76/<STRING2           {         LDS  SI,<string2[BP]     ; DS:SI = string 2}
  27.   /$AC                        {         LODSB}
  28.   /$88/$C6                    {         MOV  DH,AL               ; DH = LENGTH(string2)}
  29.   /$8A/$5E/<OPERATION         {         MOV  BL,<operation[BP]}
  30.   /$30/$FF                    {         XOR  BH,BH               ; BX = operation code}
  31.   /$08/$D2                    {         OR   DL,DL}
  32.   /$74/$2C                    {         JZ   Null                ; jump if string1 = ''}
  33.   /$08/$F6                    {         OR   DH,DH}
  34.   /$74/$23                    {         JZ   Result2             ; jump if string2 = ''}
  35.   /$88/$D1                    {         MOV  CL,DL}
  36.   /$38/$F2                    {         CMP  DL,DH}
  37.   /$72/$02                    {         JB   C1}
  38.   /$88/$F1                    {         MOV  CL,DH}
  39.   /$88/$FD                    {C1:      MOV  CH,BH               ; CX = shorter of DL or DH}
  40.   /$AC                        {CmpLoop: LODSB}
  41.   /$24/$5F                    {         AND  AL,$5F}
  42.   /$88/$C4                    {         MOV  AH,AL               ; AH = UPPER(string2[SI])}
  43.   /$26/$8A/$05                {     ES: MOV  AL,[DI]}
  44.   /$24/$5F                    {         AND  AL,$5F              ; AL = UPPER(string1[DI])}
  45.   /$38/$E0                    {         CMP  AL,AH}
  46.   /$72/$17                    {         JB   Result0             ; jump if string1 < string2}
  47.   /$77/$09                    {         JA   Result2             ; jump if string1 > string2}
  48.   /$47                        {         INC  DI}
  49.   /$E2/$ED                    {         LOOP CmpLoop}
  50.   /$38/$F2                    {         CMP  DL,DH}
  51.   /$72/$0E                    {         JB   Result0}
  52.   /$74/$09                    {         JE   Result1}
  53.   /$80/$C3/$06                {Result2: ADD  BL,6}
  54.   /$EB/$07                    {         JMP  short Result0}
  55.   /$08/$F6                    {Null:    OR   DH,DH}
  56.   /$75/$03                    {         JNZ  Result0}
  57.   /$80/$C3/$03                {Result1: ADD  BL,3}
  58.   /$2E/$8A/$87/>RESULTABLE    {Result0: CS:MOV AL,>Resultable[BX]; get function result}
  59.   /$88/$46/$0E                {         MOV  [BP+14],AL}
  60.   /$1F)                       {         POP  DS}
  61.  function result}
  62.   /$88/$46/$0E                {         MOV  [BP+14],AL}
  63.